package com.adxon.data;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

public class Following implements Iterable<Tagging>,Iterator<Tagging>{
	private Iterator<Entry<Long,Tagging>> itr;
	private long own;

	public Following(Item template){
		long o=template.getOwnerId();
		Map<Long,Tagging> p=new HashMap<Long,Tagging>();
		Star a=new Star();
		a.setOwner(o);
		StarSet m=new StarSet(a);
		for(Star i:m){
			long d=i.getId();
			Item t;
			if(d==0){
				t=new Item();
				t.setRate(9);
				t.setTags(i.getTags());
			}else{
				t=new Link();
				t.setKind();
				t.setOwner(d);
				t.setRate(19);
			}
			for(Tagging k:new ItemSet(t,null)){
				if(k.getKind()==Mark.KN)
					k=((Item)k).getRef();
				p.put(k.getId(),k);
			}
		}
		itr=p.entrySet().iterator();
		own=template.getStarer();
	}
	@Override
	public boolean hasNext(){
		return itr.hasNext();
	}
	@Override
	public Iterator<Tagging> iterator(){
		return this;
	}
	@Override
	public Tagging next(){
		Item r=((Item)itr.next().getValue());
		r.setStarer(own);
		return r;
	}
	@Override
	public void remove(){
	}
}